{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.8.5 64-bit ('pytorch1.7': conda)",
   "metadata": {
    "interpreter": {
     "hash": "9a224c36395d8457150f042128cf7a9bbee2765468c84cd10847cea80e0b645b"
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "from torchvision.datasets import ImageFolder\n",
    "import torchvision.transforms as transforms"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "path = r'D:\\GitHub\\RiceDiseasesWeb\\recognition\\dataset'\n",
    "transform = transforms.Compose([\n",
    "    transforms.Resize((80)), \n",
    "    transforms.ToTensor(), \n",
    "    transforms.Normalize([.5, .5, .5], [.5, .5, .5])\n",
    "])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "datasets = ImageFolder(root=path,transform=transform)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "Dataset ImageFolder\n",
       "    Number of datapoints: 2550\n",
       "    Root location: D:\\GitHub\\RiceDiseasesWeb\\recognition\\dataset\n",
       "    StandardTransform\n",
       "Transform: Compose(\n",
       "               Resize(size=80, interpolation=PIL.Image.BILINEAR)\n",
       "               ToTensor()\n",
       "               Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])\n",
       "           )"
      ]
     },
     "metadata": {},
     "execution_count": 14
    }
   ],
   "source": [
    "datasets"
   ]
  },
  {
   "source": [
    "得到分类名字的列表"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "['Brownspot', 'blast', 'blight', 'sheath_blight', 'tungro']"
      ]
     },
     "metadata": {},
     "execution_count": 15
    }
   ],
   "source": [
    "datasets.classes"
   ]
  },
  {
   "source": [
    "得到分类的名称以及索引的字典"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "{'Brownspot': 0, 'blast': 1, 'blight': 2, 'sheath_blight': 3, 'tungro': 4}"
      ]
     },
     "metadata": {},
     "execution_count": 16
    }
   ],
   "source": [
    "datasets.class_to_idx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}